package cn.kgc.mcartoon.controller;

import cn.kgc.mcartoon.dto.ActiveDto;
import cn.kgc.mcartoon.dto.CartoonDto;
import cn.kgc.mcartoon.dto.HotDto;
import cn.kgc.mcartoon.dto.ResultJson;
import cn.kgc.mcartoon.entity.MmCartoonDO;
import cn.kgc.mcartoon.mapper.MmCartoonMapper;
import cn.kgc.mcartoon.req.CartoonReq;
import cn.kgc.mcartoon.service.MmCartoonService;
import cn.kgc.mcartoon.utils.Constants;
import cn.kgc.mcartoon.utils.RedisClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 漫画表 前端控制器
 * </p>
 *
 * @author christopher
 * @since 2021-09-23
 */
@RestController
@RequestMapping("/api/cartoon")
@Api(value = "卡通模块")
public class MmCartoonController {

    @Autowired
    private MmCartoonService cartoonService;

    @Autowired
    private RedisClient redisClient;

    @ApiOperation("原创精品")
    @GetMapping("Origina")
    public ResultJson queryOriginaCartoon(){
        CartoonReq cartoonReq = new CartoonReq(Constants.Cartoon.Sort.HOT, 0, Constants.Home.FINISH_SIZE);
        cartoonReq.setIsOriginal(Constants.MM_YES);
        List<CartoonDto> cartoons = cartoonService.selectOriginalCartoonList(cartoonReq);
        return ResultJson.ok(cartoons);

    }

    @ApiOperation(("热门排行"))
    @GetMapping("hot")
    public ResultJson queryHotCartoon(){

        //创建查询条件，热度为1，启示为0，最大为20
        CartoonReq cartoonReq = new CartoonReq(Constants.Cartoon.Sort.HOT, 0, Constants.Home.FINISH_SIZE);

        List<HotDto> hots = cartoonService.selectHotCartoonList(cartoonReq);

        return ResultJson.ok(hots);

    }

    private ResultJson dtoHotCarton() {
        CartoonReq cartoonReq = new CartoonReq(Constants.Cartoon.Sort.HOT, 0, Constants.Home.FINISH_SIZE);
        List<HotDto> hotDtos = cartoonService.selectHotCartoonList(cartoonReq);

        return ResultJson.ok(hotDtos);

    }

    private ResultJson activeCarton(){
        CartoonReq cartoonReq = new CartoonReq(Constants.Cartoon.Sort.HOT, 0, Constants.Home.FINISH_SIZE);

        List<ActiveDto> activeDtos = cartoonService.selectActiveCartoonList();

        return ResultJson.ok(activeDtos);

    }

}

